package PAT;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;


public class PAT1034_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int limit = scanner.nextInt();
        List<List<String>> ans = new ArrayList<>();
        HashMap<String, Integer> values = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String a =scanner.next();
            String b =scanner.next();
            int v = scanner.nextInt();
            for (List<String> an : ans) {
                if(an.contains(a)){
                    values.put(a,values.get(a)+v);
                }
            }
        }
    }
}
